﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Core;
using ZHDJ.Data.Models.Common;
using ZHDJ.Data.Models.Edu;
using ZHDJ.WebPage;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.Edu
{
    public partial class PartyEduLessonMore : UseMorePageMasterPage
    {
        /// <summary>
        /// 页数
        /// </summary>
        private string PageIndex
        {
            get
            {
                return this.Request["PageIndex"] ?? "";
            }
        }

        /// <summary>
        /// 每页条数
        /// </summary>
        private string PageSize
        {
            get
            {
                return this.Request["PageSize"] ?? "";
            }
        }
        private string DataCount
        {
            get
            {
                return this.Request["DataCount"] ?? "";
            }
        }

        private string PageCategory
        {
            get { return this.Request["PageCategory"] ?? ""; }
        }
        private string PageTitle
        {
            get { return this.Request["PageTitle"] ?? ""; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ControlBusiness.ControlBindDataDictionary(ddlCategory, SysDataDictionary.EduThemeCategory, true);
            this.ddlCategory.SelectedValue = this.PageCategory;
            if (!string.IsNullOrEmpty(this.PageIndex))
            {
                this.WriteList();
                return;
            }
            else if (!string.IsNullOrEmpty(this.DataCount))
            {
                WriteDataCount();
                return;

            }
            if (!IsPostBack)
            {
                LoadData();
            }

        }
        public void LoadData()
        {
            this.hfCategory.Value = this.Category;
        }

        private void WriteList()
        {
            StringBuilder sbHtml = new StringBuilder();

            DataTable dt = PartyEduLesson.GetPartyEduCourseware(Convert.ToInt32(this.PageIndex), Convert.ToInt32(PageSize), PageCategory, this.Category, PageTitle, "4").Tables[0];
            dt.Columns.Add("ImgUrl", typeof(string));
            dt.Columns.Add("CreateTime2", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                dr["CreateTime2"] = Convert.ToDateTime(dr["CreateTime"]).ToString("yyyy-MM-dd HH:mm");
                dr["ImgUrl"] = UpFileBusiness.GetFileUrl(Convert.ToString(dr["ImageID"]));
            }
            var json = JsonConvert.SerializeObject(dt);

            Response.Clear();
            Response.Write(json);
            Response.End();
        }
        private void WriteDataCount()
        {
            Response.Clear();
            Response.Write(PartyEduLesson.GetPartyEduCourseware(0, 1, PageCategory, this.Category, PageTitle, "4").Tables[1].Rows[0][0].ToString());
            Response.End();
        }
        #region 模块菜单
        /// <summary>
        /// 初始化module  如果通过url传参可不设置
        /// </summary>
        protected override void InitModule()
        {
            Module = "EduLesson";
            //Category = "";

        }
        #endregion
    }
}